﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Events.*;
    import Display.DialogUI.*;
    import Classes.util.*;
    import Modules.bandits.*;
    import Display.*;
    import Modules.crew.*;
    import Modules.minigames.*;
    import Display.peddlerUI.*;

    public class TWorldLoad extends TFarmTransaction {

        protected var m_userId:String;
        protected var m_popup:GenericDialog;
        private var m_mission:Object;

        public function TWorldLoad(_arg1:String){
            this.m_userId = _arg1;
            Global.isTransitioningWorld = true;
            this.m_popup = UI.displayMessage(ZLoc.t("Main", "LoadingFarm"), GenericDialogView.TYPE_NOBUTTONS, null, "", true);
        }
        override public function perform():void{
            signedCall("WorldService.loadWorld", this.m_userId.toString());
        }
        override protected function onComplete(_arg1:Object):void{
            Global.player.mutualFriendsDialog = null;
            Sounds.stopAnyLoopingSounds();
            _arg1.world.ownerId = this.m_userId.toString();
            Global.franchiseManager.loadWorldObject(_arg1.franchises, _arg1.world.ownerId);
            Global.franchiseManager.placementMode = false;
            Global.world.mostFrequentHelpers = _arg1.world.mostFrequentHelpers;
            Global.world.vistorCenterText = (_arg1.world.visitorCenterMessage as String);
            Global.world.loadObject(_arg1.world);
            if (_arg1.peddlers){
                Global.peddlerManager.refreshOwnPeddlerData(_arg1.peddlers);
                Global.peddlerManager.loadObject(_arg1.peddlers);
            };
            if (_arg1.crews != null){
                Global.crews = new CrewMap();
                Global.crews.loadObject(_arg1.crews);
            };
            if (((_arg1.featureData) && (_arg1.featureData.rollCall))){
                Global.rollCallManager.loadObject(_arg1.featureData.rollCall);
            };
            var _local2:String;
            MiniGame.end();
            if (Global.player.snUser.uid != this.m_userId){
                _local2 = Global.player.getFriendName(this.m_userId);
                if (_local2 == null){
                    _local2 = ZLoc.t("Main", "Friend");
                };
                if (((Global.player.isEligibleForBusinessUpgrades()) && (!(Global.player.getSeenFlag("biz_ups_visit_toaster"))))){
                    Global.player.setSeenFlag("biz_ups_visit_toaster");
                    Global.ui.showTickerMessage(ZLoc.t("Main", "TickerBusinessUpgradesVisit"), true);
                };
            } else {
                _local2 = Global.player.snUser.firstName;
                Global.ui.m_cityNamePanel.cityName = Global.player.cityName;
                Global.hud.townName = Global.player.cityName;
            };
            if (!Global.isVisiting()){
                Global.hud.townName = Global.player.cityName;
                Global.player.commodities.updateCapacities();
                Global.hud.updateCommodities();
                if (!Global.world.citySim.banditManager.areStationsLocked()){
                    BanditManager.spawnExistingCops(true);
                };
                BanditManager.banditsSpawned.splice(0);
            };
            Global.hud.conditionallyRefreshHUD(true);
            PeddlerBar.getInstance().closePeddler();
            Global.world.centerCityView(0);
            this.m_popup.close();
            Global.isTransitioningWorld = false;
            if (Global.isVisiting()){
                Global.world.dispatchEvent(new FarmGameWorldEvent(FarmGameWorldEvent.BEGIN_VISIT));
            };
            GameTransactionManager.addTransaction(new TUpdateEnergy());
        }
        override protected function onFault(_arg1:int, _arg2:String):void{
            this.m_popup.close();
            UI.displayMessage(ZLoc.t("Main", "UnableToLoadFarm"));
        }

    }
}//package Transactions 
